<template>
  <a-modal
    :title="isEdit ? '修改精华液' : '添加明细'"
    :visible.sync="isShow"
    :confirm-loading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :maskClosable="false"
    width="30%"
    class="basic-modal"
  >
    <div class="title">
      <a-form-model
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 14 }"
        :model="essenceItem"
        ref="form"
      >
        <a-form-model-item label="精华液编码">
          <a-input
            style="width: 75%; margin-right: 5px"
            disabled
            v-model="essenceItem.MaterialCode"
          />
        </a-form-model-item>
        <a-form-model-item label="精华液名称">
          <a-input
            style="width: 75%"
            v-model="essenceItem.MaterialName"
            disabled
          />
        </a-form-model-item>
        <a-form-model-item label="批次号">
          <a-input style="width: 75%" v-model="essenceItem.BatchNo" disabled />
        </a-form-model-item>
        <a-form-model-item label="投料单号">
          <a-input style="width: 75%" v-model="essenceItem.PlanNo" disabled />
        </a-form-model-item>
        <a-form-model-item label="当前库存">
          <a-input style="width: 75%" v-model="essenceItem.CurQty" disabled />
        </a-form-model-item>

        <a-form-model-item label="可分配数量">
          <a-input
            style="width: 75%"
            v-model="essenceItem.ToDistributeQty"
            disabled
          />
        </a-form-model-item>
        <a-form-model-item label="待分配数量">
          <a-input style="width: 75%" v-model="essenceItem.SmgrQty" disabled />
        </a-form-model-item>
        <a-form-model-item label="分配数量">
          <a-input style="width: 75%" v-model="essenceItem.AllocatedQty" />
        </a-form-model-item>
      </a-form-model>
    </div>
  </a-modal>
</template>

<script>
import { updSemiMGoodsDistributeDetail } from "@/api/SemiMGoodsDistributeDetail/index";
export default {
  components: {},
  props: {
    isShow: {
      type: Boolean,
      default: false,
    },
    essenceItem: {
      type: Object,
      default: {},
    },
    isEdit: {
      type: Boolean,
      default: false,
    },
  },
  model: {
    prop: "isShow",
    event: "close",
  },

  data() {
    return {
      feedShow: false,
      confirmLoading: false, //modal的loading
      formItem: { planNoText: null, packingPlanNo: null },
    };
  },
  methods: {
    /** 修改精华液预分配 */
    async upData() {
      try {
        let res = await updSemiMGoodsDistributeDetail(this.essenceItem);
        if (res.Status == 10000) {
          this.$message.success("修改成功");
          this.$emit("up-data");
          this.handleCancel();
        } else {
          this.$message.error(res.Message);
        }
      } catch (e) {
        this.$message.error(e);
      }
    },

    //关闭弹窗
    handleCancel() {
      this.$emit("close", false);
    },
    //确认添加/修改
    async handleOk() {
      this.confirmLoading = true;
      try {
        if (!this.essenceItem.AllocatedQty)
          return this.$message.error("请先填写预分配数量");
        await this.upData();
      } catch {
      } finally {
        this.confirmLoading = false;
      }
    },
  },
};
</script>

<style lang="less" scoped></style>
